<template>
    <div class="selectTime">
        <group>
            <popup-picker title="请选择日期" :data="dateList" v-model="date"  placeholder="请选择日期"></popup-picker>
        </group>
        <group>
            <popup-picker title="请选择时间" :data="timeList" v-model="time"  placeholder="请选择时间"></popup-picker>
        </group>
        <div class="btn" @click="confirmOrder()">
            <span>确定预约</span>
        </div>
    </div>
</template>

<script>
import { PopupPicker, Group } from "vux";
import { getStore, setStore, removeStore } from "../config/mUtils";
import api from "../fetch/api";
export default {
  components: {
    PopupPicker,
    Group
  },
  data() {
    return {
      date: [], //选中的日期值
      time: [], //选中的时间值
      dateList: [], //日期列表
      timeList: [] //时间列表
    };
  },
  activated() {
    let currentType = "";
    if (this.$route.query.type === "RepayAheadsome") {
      currentType = "部分提前还款";
    } else if (this.$route.query.type === "RepayAheadall") {
      currentType = "提前全部结清";
    } else if (this.$route.query.type === "RepayNormalall") {
      currentType = "自然结清";
    } else if (this.$route.query.type === "ChangeCard") {
      currentType = "变更扣款账号";
    } else if (this.$route.query.type === "ChangeWay") {
      currentType = "变更还款方式";
    } else if (this.$route.query.type === "ChangeDay") {
      currentType = "变更还款日";
    } else if (this.$route.query.type === "ChangeDeadtime") {
      currentType = "变更还款期限";
    } else if (this.$route.query.type === "GetData") {
      currentType = "结清资料领取";
    } else if (this.$route.query.type === "GetPlan") {
      currentType = "还款计划";
    } else if (this.$route.query.type === "GetList") {
      currentType = "还款清单";
    } else if (this.$route.query.type === "GetBook") {
      currentType = "证书借阅";
    }
    let data = {
      token: getStore("token"),
      type: currentType
    };
    api.get_appoint_date(data).then(res => {
      if (res.success) {
        this.dateList.push(res.dates);
        this.timeList.push(res.times);
      }
    });
  },
  deactivated() {
    this.dateList = [];
    this.timeList = [];
    this.date = [];
    this.time = [];
  },
  methods: {
    confirmOrder() {
      let currentType = "";
      let data = "";
      if (!this.date) {
        this.$vux.toast.text("请选择日期");
      } else if (!this.time) {
        this.$vux.toast.text("请选择时间");
      } else {
        if (this.$route.query.type.indexOf("Repay") !== -1) {
          if (this.$route.query.type === "RepayAheadsome") {
            currentType = "部分提前还款";
          } else if (this.$route.query.type === "RepayAheadall") {
            currentType = "提前全部结清";
          } else if (this.$route.query.type === "RepayNormalall") {
            currentType = "自然结清";
          }
          data = {
            token: getStore("token"),
            lonnbr: this.$route.query.lonnbr,
            type: currentType,
            amt: this.$route.query.mount,
            date: this.date[0],
            time: this.time
          };
        } else if (this.$route.query.type.indexOf("Change") !== -1) {
          if (this.$route.query.type === "ChangeCard") {
            currentType = "变更扣款账号";
            data = {
              token: getStore("token"),
              type: currentType,
              date: this.date[0],
              time: this.time
            };
          } else if (this.$route.query.type === "ChangeWay") {
            currentType = "变更还款方式";
            data = {
              token: getStore("token"),
              type: currentType,
              oldcon:this.$route.query.oldWay,
              newcon:this.$route.query.newWay,
              date: this.date[0],
              time: this.time
            };
          } else if (this.$route.query.type === "ChangeDay") {
            currentType = "变更还款日";
            data = {
              token: getStore("token"),
              type: currentType,
              oldcon:this.$route.query.oldDay,
              newcon:this.$route.query.newDay,
              date: this.date[0],
              time: this.time
            };
          } else if (this.$route.query.type === "ChangeLoanDeadline") {
            currentType = "变更还款期限";
            data = {
              token: getStore("token"),
              type: currentType,
              date: this.date[0],
              time: this.time
            };
          }
        } else if (this.$route.query.type.indexOf("Get") !== -1) {
          if (this.$route.query.type === "GetData") {
            currentType = "结清资料领取";
          } else if (this.$route.query.type === "GetPlan") {
            currentType = "还款计划";
          } else if (this.$route.query.type === "GetList") {
            currentType = "还款清单";
          } else if (this.$route.query.type === "GetBook") {
            currentType = "证书借阅";
          }
          data = {
            token: getStore("token"),
            type: currentType,
            date: this.date[0],
            time: this.time
          };
        }
        api.get_pay(data).then(res => {
          this.$router.push("/book/success");
        });
      }
    }
  }
};
</script>

<style lang="less" scoped>
.selectTime {
}
</style>

